import { observable, action, useStrict, computed, asMap, toJS } from 'mobx';
import BaseStore from './BaseStore';
import * as API_REQ from '../apis/form';
import { Tools } from 'weaver-mobile';
import * as mobx from 'mobx';
import base from '../util/base';
import { _ } from '../util/pcPublic';
import { getLabel } from '../util/common';

const initState = {
    tabKey: "0",
    datas: [],
}

export class ResourceStore extends BaseStore{

    @observable tabKey;
    @observable datas;

    constructor(){
        super();
        this.loadData = this.loadData.bind(this);
        this.switchTab = this.switchTab.bind(this);
    }

    @action("切换Tab")
    switchTab(tabKey){
        this.tabKey = tabKey;
    }

    @action
    loadData(params={}){
        let reqParams = {tabindex:"0"};     //全部相关资源
        const range = ["requestid", "isrequest", "desrequestid", "iswfshare", "authStr", "authSignatureStr", "f_weaver_belongto_userid", "f_weaver_belongto_usertype","nodeid","iscowork","coworkid","isurger"];
        range.map(key =>{
            reqParams[key] = params[key];
        });
        console.log("reqParams", reqParams);
        API_REQ.getResourcesKey(reqParams).then(data =>{
            const sessionkey = data.sessionkey || "";
            if(sessionkey !== ""){  //请求datas接口取具体数据
                Tools.callApi({
                    url: "/api/ec/dev/table/datas",
                    method: "POST",
                    params: {dataKey:sessionkey, pageSize:9999, ismobile:1}     //不分页请求全部数据
                }).then(result =>{
                    console.log("result", result);
                    this.datas = result.datas;
                });
            }
        });
    }

}